<?php
$yuer = 2018;
$month = 4;
if ($yuer % 4 == 0 && $yuer % 100 != 0 || $yuer % 400 == 0) {
	$tian=366;
} else {
	$tian=365;
};
switch ($month) {
	case 1 :
	case 3 :
	case 5 :
	case 7 :
	case 8 :
	case 10 :
	case 12 :
		$day=31;
		break;

	case 4 :
	case 6 :
	case 9 :
	case 10 :
	case 11 :
		$day=30;
		break;
	case 2 :
		if ($yuer % 4 == 0 && $yuer % 100 != 0 || $yuer % 400 == 0) {
		 $day=29;
		} else {
		 $day=28;
		};
		break;
};
$moneday = date("w",mktime(0,0,0,$month,'1',$yuer)); //获取该月的1号星期几
echo $moneday;
$day31 = ($moneday + $day - 1) % 7;//当前月最后一天星期几
echo "<table width='600' border='1' style='text-align: center;'>";
echo "<tr><td colspan='7'>{$yuer}年共有{$tian}天{$month}月{$day}天<br/></td></tr>";
echo "<tr><th>日</th><th>一</th><th>二</th><th>三</th><th>四</th><th>五</th><th>六</th></tr>";
echo "<tr>";
for($n=0;$n<$moneday;$n++){
		echo "<td></td>";
	}
for ($i=1; $i <=$day ; $i++) {
if(($i + $moneday - 1) % 7 == 0 && $i != 1) {
   echo "</tr>";
 }
echo "<td>$i</td>";
}

for($a = 1; $a < 7 - $day31; $a++){
echo "<td ></td>";
if($a == 6 - $day31) {
echo "</tr>";
}
}
echo "</table>";
?>